<?php

/**
 * This is the model class for table "answers".
 *
 * The followings are the available columns in table 'answers':
 * @property integer $answers_id
 * @property integer $answers_checks_id
 * @property integer $answers_qid
 * @property string $answers_result
 * @property string $answers_create_time
 * @property string $answers_edit_time
 */
class Answers extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Answers the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'answers';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('answers_checks_id, answers_qid', 'numerical', 'integerOnly'=>true),
			array('answers_result, answers_create_time, answers_edit_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('answers_id, answers_checks_id, answers_qid, answers_result, answers_create_time, answers_edit_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'checks'=>array(self::BELONGS_TO,'Checks','answers_checks_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'answers_id' => '考生答卷',
			'answers_checks_id' => '考生参考名称',
			'answers_qid' => '考试试题',
			'answers_result' => '答题结果',
			'answers_create_time' => '创建时间',
			'answers_edit_time' => '修改时间',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('answers_id',$this->answers_id);

		$criteria->compare('answers_checks_id',$this->answers_checks_id);

		$criteria->compare('answers_qid',$this->answers_qid);

		$criteria->compare('answers_result',$this->answers_result,true);

		$criteria->compare('answers_create_time',$this->answers_create_time,true);

		$criteria->compare('answers_edit_time',$this->answers_edit_time,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	public function beforeSave() {
		if(parent::beforeSave()){
			if($this->isNewRecord){
				$this->answers_create_time = $this->answers_edit_time = date("Y-m-d H:i:s");
			}else{
				$this->answers_edit_time = date("Y-m-d H:i:s");
			}
			return true;
		}else{
			return false;
		};
	}
	
}